package com.fjxd.people.web;

import com.fjxd.feign.result.ViewResult;
import com.fjxd.people.pojo.People;
import com.fjxd.people.service.PeopleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/people")
public class PeopleController {
    @Autowired
    private PeopleService peopleService;
    /*
    * 查找账号下的所有人员信息
    * */
    @GetMapping("/{userId}")
    public List<People> getPeopleForUser(@PathVariable Integer userId){
        return peopleService.getPeopleForUser(userId);
    }

    @GetMapping("/getPeople/{peopleid}")
    public People getPeople(@PathVariable Integer peopleid) {
        return peopleService.getPeople(peopleid);

    }
//    @GetMapping("/getManyPeople/{peole}")
    /*
     * 添加购票人
     * */
    @PostMapping("/{id}")
    public ViewResult savePeople(@PathVariable Integer id, @RequestBody People people) {
        return peopleService.savePeople(id, people);
    }

    /*
    * 删除购票人
    * */
    @DeleteMapping("/{id}")
    public ViewResult deletePeople(@PathVariable Integer id){
        return peopleService.deletePeople(id);
    }

    /*
     * 修改购票人
     * */
    @PutMapping("/{id}")
    public ViewResult updatePeople(@PathVariable Integer id, @RequestBody People people) {
        System.out.println(people);
        return peopleService.updatePeople(id, people);
    }

}
